package com.dlc.apk.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import com.jeremyliao.liveeventbus.LiveEventBus


class NetworkChangeReceiver : BroadcastReceiver() {
    companion object {
        const val NETWORK_CHANGE_EVENT = "network change event"
    }

    override fun onReceive(context: Context, intent: Intent) {
        val connectionManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = connectionManager.activeNetworkInfo
        LiveEventBus.get(NETWORK_CHANGE_EVENT).post(networkInfo != null && networkInfo.isAvailable)
    }
}